package com.surprise.db.dao.join;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.surprise.db.dao.SimpleDAO;
import com.surprise.db.entity.join.SelectMall002Entity;

/**
 * SelectMall002.java
 * @author xuling
 * @since 2017年2月14日
 */
@Repository
public class SelectMall002 extends SimpleDAO<SelectMall002Entity> {

	/**
	 * 获得用户已关注的商场信息
	 * @param userid 用户ID
	 * @return 已关注的商场信息
	 */
	public List<SelectMall002Entity> select(Long userid) {
		String sql = " SELECT mall.id, mall.name, mall.address, mall.logoPic, mall.projectPic, " + 
					 " mall.prefix,  " + 
					 " cityA.name as cityName, cityB.name as areaName, " + 
					 " COUNT(DISTINCT mall_userB.userid) as likeCount, " + 
					 " COUNT(DISTINCT pm_things_mst.id) as msgCount " + 
					 " FROM mall  " + 
					 " INNER JOIN mall_user mall_userA ON mall.id = mall_userA.mallid AND mall_userA.deleteflg = 0 and mall_userA.userid = ? " + 
					 " LEFT JOIN mall_user mall_userB ON mall.id = mall_userB.mallid AND mall_userB.deleteflg = 0 " + 
					 " LEFT JOIN pm_things_mst on mall.id = pm_things_mst.mallid " + 
					 " LEFT JOIN city cityA ON mall.cityid = cityA.id " + 
					 " LEFT JOIN city cityB ON mall.districtid = cityB.id " + 
					 " GROUP BY mall.id, mall.name, mall.address, mall.logoPic, mall.projectPic, " + 
					 " mall.prefix";
		return super.findBySql(sql, userid);
	}
}
